package com.atguigu.demo.springbootredislettuce.demo;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;

import java.util.List;

public class LettuceDemo {
    public static void main(String[] args) {
        //1.使用构建器链式变成来builder我们RedisURI
        RedisURI uri = RedisURI.builder().redis("192.168.40.100").withPort(6379).withAuthentication("default","atguigu").build();
        //2.创建连接客户端
        RedisClient redisClient = RedisClient.create(uri);
        StatefulRedisConnection connect = redisClient.connect();
        //3。通过connect创建操作的command
        RedisCommands commands = connect.sync();
        //业务逻辑
        List keys = commands.keys("*");
        System.out.println(keys);
        String k9 = commands.set("k9", "hello-lettuce");
        System.out.println(k9);
        //4。各种关闭释放资源
        connect.close();
        redisClient.shutdown();
    }
}
